package com.swing.sky.web.api.controller.monitor;


import com.swing.sky.common.annotation.Log;
import com.swing.sky.common.enums.BusinessTypeEnum;
import com.swing.sky.framework.domain.AjaxResult;
import com.swing.sky.framework.page.TableDataInfo;
import com.swing.sky.framework.utils.ExcelUtils;
import com.swing.sky.web.api.controller.BaseController;
import com.swing.sky.web.monitor.domain.SysLoginInfo;
import com.swing.sky.web.monitor.service.ISysLoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统访问记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLogininforController extends BaseController {
    @Autowired
    private ISysLoginInfoService logininforService;

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLoginInfo logininfor) {
        startPage();
        List<SysLoginInfo> list = logininforService.selectLoginInfoList(logininfor);
        return getDataTable(list);
    }

    @Log(title = "登陆日志", businessType = BusinessTypeEnum.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
    @GetMapping("/export")
    public AjaxResult export(SysLoginInfo logininfor) {
        List<SysLoginInfo> list = logininforService.selectLoginInfoList(logininfor);
        ExcelUtils<SysLoginInfo> util = new ExcelUtils<SysLoginInfo>(SysLoginInfo.class);
        return util.exportExcel(list, "登陆日志");
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登陆日志", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds) {
        return toAjax(logininforService.deleteLoginInfoByIds(infoIds));
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登陆日志", businessType = BusinessTypeEnum.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean() {
        logininforService.cleanLoginInfo();
        return AjaxResult.success();
    }
}
